package com.zenithmind.note.pojo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 分享类型枚举
 * 
 * @author ZenithMind
 * @since 2024-01-01
 */
@Getter
@AllArgsConstructor
public enum ShareType {
    
    /**
     * 链接分享
     */
    LINK(0, "链接分享"),
    
    /**
     * 朋友圈分享
     */
    MOMENTS(1, "朋友圈"),
    
    /**
     * 微信好友分享
     */
    WECHAT_FRIEND(2, "微信好友"),
    
    /**
     * QQ分享
     */
    QQ(3, "QQ"),
    
    /**
     * 微博分享
     */
    WEIBO(4, "微博"),
    
    /**
     * 邮件分享
     */
    EMAIL(5, "邮件");
    
    /**
     * 类型码
     */
    private final Integer code;
    
    /**
     * 类型描述
     */
    private final String description;
    
    /**
     * 根据类型码获取枚举
     * 
     * @param code 类型码
     * @return 分享类型枚举
     */
    public static ShareType fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        
        for (ShareType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        
        throw new IllegalArgumentException("未知的分享类型码: " + code);
    }
    
    /**
     * 判断是否为社交媒体分享
     * 
     * @return 是否为社交媒体分享
     */
    public boolean isSocialMedia() {
        return this == MOMENTS || this == WECHAT_FRIEND || this == QQ || this == WEIBO;
    }
}
